"use strict";

function Page(e) {
  var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  this.el = document.querySelector(e), this.options = t, this.options.pageInfo.totalPage = Math.ceil(this.options.pageInfo.totalData / this.options.pageInfo.pageSize), this.init();
}Page.prototype.init = function () {
  this.bindEvent(), this.createTag();
}, Page.prototype.bindEvent = function () {
  var _this = this;

  this.el.onclick = function (e) {
    var e = e || window.event,
        t = e.target || e.srcElement;if ("P" === t.nodeName) {
      switch (t.innerText) {case _this.options.pageTag.first:
          _this.options.pageInfo.pageNum = 1;break;case _this.options.pageTag.prev:
          if (1 === _this.options.pageInfo.pageNum) return;_this.options.pageInfo.pageNum--;break;case _this.options.pageTag.next:
          if (_this.options.pageInfo.pageNum === _this.options.pageInfo.totalPage) return;_this.options.pageInfo.pageNum++;break;case _this.options.pageTag.last:
          _this.options.pageInfo.pageNum = _this.options.pageInfo.totalPage;break;default:
          0 < parseInt(t.innerHTML) && (_this.options.pageInfo.pageNum = parseInt(t.innerHTML));}_this.createTag(), _this.options.callback && _this.options.callback(_this.options.pageInfo.pageNum);
    }
  };
}, Page.prototype.createTag = function () {
  this.el.innerHTML = "";var e,
      t = this.options.pageTag;for (e in t) {
    this.createP("p", t[e], this.el, !0);
  }var i = this.el.querySelectorAll("p");this.options.pageInfo.pageNum <= 1 && (i[0].style.cursor = "default", i[1].style.cursor = "default"), this.options.pageInfo.pageNum >= this.options.pageInfo.totalPage && (i[3].style.cursor = "default", i[4].style.cursor = "default"), this.createNum();
}, Page.prototype.createNum = function () {
  var t = this.el.querySelector("p:nth-child(3)");t.style.border = "none", t.style.margin = "0px", t.style.padding = "0px";var e = this.options.pageInfo.pageNum,
      i = this.options.pageInfo.totalPage;if (i < 7) for (var _e = 1; _e <= i; _e++) {
    this.createP("p", _e, t);
  } else if (e < 5) {
    for (var _e2 = 1; _e2 <= 5; _e2++) {
      this.createP("p", _e2, t);
    }this.createP("p", "...", t), this.createP("p", i - 1, t), this.createP("p", i, t);
  } else if (5 == e) {
    for (var _e3 = 1; _e3 <= 7; _e3++) {
      this.createP("p", _e3, t);
    }this.createP("p", "...", t), this.createP("p", i - 1, t), this.createP("p", i, t);
  } else if (5 < e && e < i - 4) {
    for (var _e4 = 1; _e4 <= 2; _e4++) {
      this.createP("p", _e4, t);
    }this.createP("p", "...", t), this.createP("p", e - 2, t), this.createP("p", e - 1, t), this.createP("p", e, t), this.createP("p", e + 1, t), this.createP("p", e + 2, t), this.createP("p", "...", t), this.createP("p", i - 1, t), this.createP("p", i, t);
  } else if (i - 4 <= e) {
    for (var _e5 = 1; _e5 <= 2; _e5++) {
      this.createP("p", _e5, t);
    }this.createP("p", "...", t);for (var _e6 = i - 4; _e6 <= i; _e6++) {
      this.createP("p", _e6, t);
    }
  }
}, Page.prototype.createP = function (e, t, i, a) {
  var o = document.createElement(e);o.innerText = t, o.style.border = "solid 1px #e5e5e5", o.style.margin = "0 5px", o.style.padding = "10px 15px", o.style.textAlign = "center", o.style.display = "inline-block", o.style.color = "#fff", o.style.cursor = "pointer", a ? o.style.color = "#999" : o.style.background = "#13d1be", t == this.options.pageInfo.pageNum && (o.style.background = "orange", o.style.cursor = "default"), i.appendChild(o);
};